<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>KKJSBridge FormData</title>
<style>
    button {
        background:#000;
        color:#fff;
        padding: 6px 12px;
        font-size: 14px;
        display:block;
        margin-bottom:5px;
        border:none;
        border-radius: 3px;
    }
</style>
</head>
<body>
    <a href="http://jsfiddle.net/gh/get/extjs/4.2/icattlecoder/jsfiddle/tree/master/uptoken">可以在这里生成七牛token</a>
    <input id="file" name="file" type="file" />
	<button onclick="sendFormData()">上传文件到七牛</button>
</body>
<script src="https://cdn.bootcss.com/eruda/1.5.2/eruda.min.js"></script>
<script>eruda.init();</script>
<script type="text/javascript">
    function sendFormData() {
        var file = document.getElementById('file').files[0];

        var formData = new FormData();
        formData.append('key', 'bbbb');
        formData.append('token', 'RSxpQIxNIS2vo0vuQR3HX701ddS9fdlUnQ5jV8u1:rKwNt9zzmjn1FodGG03k-McLF28=:eyJzY29wZSI6Imthcm9zcGljcyIsImRlYWRsaW5lIjoxNTY5Nzg4OTQwfQ==');
        formData.append('file', file);
        
        var xhr = new XMLHttpRequest();
        xhr.open('POST', 'http://upload.qiniup.com/', true);
        xhr.onreadystatechange = () => {
            if (xhr.status === 200 && xhr.readyState === 4) {
              console.log(xhr.responseText);
            }
        };
        xhr.onerror = function (e) {
            console.log(e);
        };
        xhr.send(formData);
    }
</script>
</html>
